package com.itdianzi.service.cargo.impl;

import com.alibaba.dubbo.config.annotation.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import com.itdianzi.dao.cargo.PackingDao;
import com.itdianzi.domain.cargo.Packing;
import com.itdianzi.domain.cargo.PackingExample;
import com.itdianzi.service.cargo.PackingService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;
import java.util.List;
import java.util.UUID;

@Service
public class PackingServiceImpl implements PackingService {

    @Autowired
    private PackingDao packingDao;
    @Override
    public void save(Packing packing) {
        packing.setCreateTime(new Date());
        packing.setState(0L);
        packing.setPackingListId(UUID.randomUUID().toString());
        packingDao.insertSelective(packing);
    }
    @Override
    public PageInfo findByPage(PackingExample packingExample, Integer page, Integer size) {
        PageHelper.startPage(page,size);
        List<Packing> packings = packingDao.selectByExample(packingExample);
        return new PageInfo(packings);
    }

    @Override
    public Packing findById(String id) {
        Packing packing = packingDao.selectByPrimaryKey(id);
        return packing;
    }

    @Override
    public void update(Packing packing) {
        packingDao.updateByPrimaryKeySelective(packing);
    }

    @Override
    public List<Packing> findAll(String companyId) {
        PackingExample packingExample = new PackingExample();
        PackingExample.Criteria criteria = packingExample.createCriteria();
        criteria.andCompanyIdEqualTo(companyId);
        return packingDao.selectByExample(packingExample);
    }

    @Override
    public void delete(String id) {
        packingDao.deleteByPrimaryKey(id);
    }
}
